<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Auth extends CI_Controller {
	public function login(){	
		// $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        $this->form_validation->set_error_delimiters('<span class="help-block error">', '</span>');
        $this->form_validation->set_rules('username', '用户名', 'required|callback_username_check');
		$this->form_validation->set_rules('password', '密码', 'required');
        if ($this->form_validation->run() == FALSE){
            $this->load->view('admin/login');
        }else{
            $this->session->set_userdata('is_login', true);
            redirect("/admin/article/index");
        }
	}
	public function username_check(){
		$username = $this->input->post('username');
		$password = md5($this->input->post('password'));
		$this->load->model("Admin_model");
        if ($this->Admin_model->get_One($username,$password)){
            $_SESSION['name'] = $username;
        	return TRUE;	  
        }else{
            $this->form_validation->set_message('username_check', '用户名或密码不正确');
            return FALSE;
    		}
    }
}
?>